﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace ChuongtrinhTracnghiem.Model
{
    class Test
    {
 
        public string ThoigianTest(int tg)
        {
            int gio = 0, phut = 0, giay = 0;
            gio = tg / 3600;
            tg = tg - gio * 3600;
            phut = tg / 60;
            giay = tg - phut * 60;
            return (gio.ToString() + ":" + phut.ToString() + ":" + giay.ToString());
        }

        public int  RanddomNumber(int min, int max)
        {
            Random rd = new Random();
            return rd.Next(min, max);
        }

        public int[] Taomangcauhoi(int socau)
        {
            int[] mang = new int[100];
            int so = RanddomNumber(0, socau);
            mang[0] = so;
            for (int i = 1; i < socau; i++)
            {
                do
                {
                    so = RanddomNumber(0, socau);
                    for (int k = 0; k < i; k++)
                    {
                        if (so == mang[k])
                        {
                            so = -1;
                            break;
                        }
                    }
                }
                while (so == - 1);
                mang[i] = so;
            }
            return mang;
        }

        public char[] Khoitaomangtraloi(int socau)
        {
            char[] mang = new char[100];
            for (int j = 0; j < socau; j++)
                {
                    mang[j] = 'F';
                }
            return mang;
        }
         
        //Tạo mảng đáp án

        public char[] Taomangdapan(int socau, DataTable ds, int[] mangcauhoi )
        {
            char[] mang = new char[100];
            for (int k = 0; k < socau; k++)
            {
                mang[k] = Convert.ToChar(ds.Rows[mangcauhoi[k]]["Caudung"].ToString());

            }
            return mang;
        }

        public int Chamdiem(int socau, char [] mangtraloi, char [] mangdapan )
        {
            int i = 0, caudung=0;
            for (i = 0; i < socau; i++)
            {
                if (mangtraloi[i] == mangdapan[i])
                    caudung++;
            }
            return (caudung);
        }
    }
}
